package org.example.knowledgegraph.service;

import org.example.knowledgegraph.model.Movie;
import org.example.knowledgegraph.model.Person;
import org.example.knowledgegraph.model.Relation;
import org.example.knowledgegraph.repository.EntityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class KnowledgeGraphService {

    @Autowired
    private EntityRepository entityRepository;

    public Person findByName(String name) {
        return entityRepository.findByName(name);
    }

    public List<Person> findAll() {
        return entityRepository.findAll();
    }

    public Set<Movie> getMovieByRelationship(Person person, String rel){
        if(rel.equals("actedby")){
            return  person.getActedInMovie();
        } else if (rel.equals("directed")) {
            return person.getDirectedMovie();
        } else if (rel.equals("wrote")) {
            return person.getWroteMovie();
        } else if (rel.equals("reviewed")) {
            return person.getReviewedMovie();
        } else if (rel.equals("produced")) {
            return person.getProduceMovie();
        }
        else {
            return null;
        }
    }
}
